<?php
/**
 * 自定义的 ini 配置文件处理部分
 *
 * 处理 true,false, 原始的 Zend_Config_Ini 无法处理，这里简单的hook一下
 *
 * @final
 * @package Crmlite_Config
 * @version $Id: Ini.php 8 2007-08-20 10:03:56Z etng2004 $
 * @copyright 2006-2007 ETE.CN
 * @author Yi BO  <etng2004@gmail.com>
 * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
 */

/**
 * @see Zend_Config
 */
require_once 'Zend/Config/Ini.php';


/**
 * @category   Zend
 * @package    Zend_Config
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Crmlite_Config_Ini extends Zend_Config_Ini
{

    /**
     * Assign the key's value to the property list. Handle the "dot"
     * notation for sub-properties by passing control to
     * processLevelsInKey().
     *
     * @param array $config
     * @param string $key
     * @param string $value
     * @throws Zend_Config_Exception
     * @return array
     */
    protected function _processKey($config, $key, $value)
    {
        if (strpos($key, $this->_nestSeparator) !== false) {
            $pieces = explode($this->_nestSeparator, $key, 2);
            if (strlen($pieces[0]) && strlen($pieces[1])) {
                if (!isset($config[$pieces[0]])) {
                    $config[$pieces[0]] = array();
                } elseif (!is_array($config[$pieces[0]])) {
                    throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists");
                }
                $config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value);
            } else {
                throw new Zend_Config_Exception("Invalid key '$key'");
            }
        } else {
        	if($value === 'BOOL_TRUE')$value = true;
        	if($value === 'BOOL_FALSE')$value = false;
            $config[$key] = $value;
        }
        return $config;
    }

}
